package com.upstairstechnology.oi.notification;

import java.io.IOException;
import java.util.Set;

import javax.mail.MessagingException;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Required;

import com.upstairstechnology.oi.determination.OutstandingIntegration;

/**
 * Default implementation of a notification handler.
 * 
 * @author Jeff Jensen
 */
public class NotificationHandlerDefault implements NotificationHandler {
    /** Logger instance. */
    private static final Logger LOGGER =
            LoggerFactory.getLogger(NotificationHandlerDefault.class);

    /** Notification strategies used to communicate outstanding integrations. */
    private Set<NotificationStrategy> notificationStrategies;

    /**
     * {@inheritDoc}
     */
    public void handle(Set<OutstandingIntegration> oiSet) throws IOException,
            MessagingException {
        LOGGER.info("notificationStrategies={}", notificationStrategies);
        for (NotificationStrategy strategy : notificationStrategies) {
            LOGGER.debug("Processing notification strategy={}", strategy);
            strategy.notify(oiSet);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    /**
     * Get the set of notification strategies.
     * 
     * @return The notification strategy.
     */
    public Set<NotificationStrategy> getNotificationStrategies() {
        return notificationStrategies;
    }

    /**
     * Set the set of notification strategies.
     * 
     * @param set
     *            The notification strategies set.
     */
    @Required
    public void setNotificationStrategies(Set<NotificationStrategy> set) {
        this.notificationStrategies = set;
    }
}
